# -*- mode: python; -*-

import pxtrace
import px

# The UPID of the simple-gotracing-example server. You can
# get the value of this by running:
# px run px/upids -- --namespace px-demo-gotracing
# The relevant UPID will be in the fourth column.
upid = 'replace-me-with-upid'

# This is the basic trace function. Every function call of
# `main.computeE` is traced and the values are recorded into
# a table as specified by the return value. 
#
# To probe struct functions, see the notes here: 
# https://docs.pixielabs.ai/tutorials/simple-go-tracing/#formatting-the-pxtrace.probe-path
@pxtrace.probe("main.computeE")
def probe_func():
    return [{
        'iterations': pxtrace.ArgExpr("iterations"),
        'latency': pxtrace.FunctionLatency(),
    }]

# This is the function that actually installs the tracepoint.
# The arguments are:
#    Tracepoint name.
#    Output table name.
#    Name of the probe function.
#    The UPID.
#    The TTL of the tracepoint. It is updated each time the script is run.
pxtrace.UpsertTracepoint('compute_e_data',
                         'compute_e_data',
                         probe_func,
                         px.uint128(upid),
                         "5m")

# This just writes the output into a table.
px.display(px.DataFrame(table='compute_e_data'))
